package com.yuanzong.wuliu.service.business.customer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanzong.wuliu.common.vo.ApiResultPage;
import com.yuanzong.wuliu.mapper.business.customer.BusinessCustomerMapper;
import com.yuanzong.wuliu.model.business.customer.BusinessCustomer;
import com.yuanzong.wuliu.model.business.customer.query.*;
import com.yuanzong.wuliu.service.business.customer.IBusinessCustomerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service("businessCustomerService")
public class BusinessCustomerServiceImpl extends ServiceImpl<BusinessCustomerMapper, BusinessCustomer> implements IBusinessCustomerService {

    // 逻辑删除
    protected static final boolean logicalDeleted = false;

    @Autowired
    private BusinessCustomerMapper businessCustomerMapper;

    //========================================================================================//
    // Service服务接口操作
    //========================================================================================//

    @Override
    public List<BusinessCustomer> querySubject(BusinessCustomerListQuery query) throws Exception {
        List<BusinessCustomer> businessCustomerList = null;
        QueryWrapper<BusinessCustomer> queryWrapper = new QueryWrapper<>();
        businessCustomerList = super.getBaseMapper().selectList(queryWrapper);
        return businessCustomerList;
    }

    @Override
    public ApiResultPage<BusinessCustomer> pageSubject(BusinessCustomerPageQuery query) throws Exception {
        ApiResultPage<BusinessCustomer> businessCustomerPageList = null;
        Page<BusinessCustomer> businessCustomerPage = new Page<>(query.getPageNum(), query.getPageSize());
        QueryWrapper<BusinessCustomer> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(query.getPhoneLike())) {
            queryWrapper.like("phone", query.getPhoneLike());
        }
        businessCustomerPage = super.baseMapper.selectPage(businessCustomerPage, queryWrapper);
        businessCustomerPageList = ApiResultPage.create(query.getPageNum(), query.getPageSize(), businessCustomerPage);
        return businessCustomerPageList;
    }

    @Override
    public BusinessCustomer queryByPhone(String phone) throws Exception {
        QueryWrapper<BusinessCustomer> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone", phone);
        return this.baseMapper.selectOne(queryWrapper);
    }

    //========================================================================================//
    // HTTP服务接口操作
    //========================================================================================//

    //========================================================================================//
    // extend methods
    //========================================================================================//


    //========================================================================================//
    // The end
    //========================================================================================//

}
